package bat;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;

import javax.per.toolkit.file.FileUtil;
import javax.per.toolkit.search.ff;
import javax.per.toolkit.search.ffijs;
import javax.per.toolkit.tools.Fun;

import tools.Env;

public class updatebat {
	
	public static void main(String[] args){
		boolean exec=false;
		for(String str:args){
			if(str.equalsIgnoreCase("-update")){
				exec=true;
				break;
			}
		}
		if(exec){
			String op=Fun.getConsoleString();
			if(op.equalsIgnoreCase("ff")){
				ff.preff(null);
			}else if(op.equalsIgnoreCase("ffijs")){
				ffijs.preffijs(null);
			}
		}else{
			gene();
		}
	}
	
	private static void gene(){
		Class<?> cla=updatebat.class;
		String batName="update";
		String parm="-update";
		String batPath=Env.get("batPath")+File.separator+batName+".bat";
		try {
			BufferedWriter bw=FileUtil.getWriter(batPath);
			bw.write("@echo off\n");
			bw.write("call initjava.bat\n");
			bw.write("java "+cla.getName()+" "+parm+" \n");
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
